<template>
	<view>
				<view class="page-box">
					<view class="order" v-for="job in jobslist" :key="job._id">
						<view class="item">
							<view class="content">
								<view class="title u-line-2">{{job.job_name}}</view>
								<view class="type">{{job.educationalRequirements}}</view>
								<!-- <view class="type" @click="selectById(job.c_id)">{{company_name}}</view> -->
							</view>
							
							<view class="right">
								<view class="price">
									{{job.job_salary}}
								</view>
								<u-button type="primary" size="mini" style="margin: 5px;" @click="showModalAndSelectCompany(job.c_id,job)">申请</u-button>
							</view>
						</view>
						
					</view>
					
				</view>
				<!-- 确认框 -->
				<u-modal v-model="modelShow" :show-cancel-button="true" :content="content" @confirm="confirm" ref="uModal" :async-close="true"></u-modal>
	</view>
</template>

<script>
export default {
	name:'hotjob',
	data() {
		name:'hotjob'
		return {
			jobslist:[],
			company_name:'点击此处查看公司',
			//模态框 确认框的显示与隐藏
			modelShow:false,
			//确认框内容
			content:'确定申请该岗位吗？',
			//接受公司名字
			companyName:'',
			//当前工作对象
			job:{},
		};
	},
	onLoad() {
		this.showCategoryJob()
	},
	computed: {
		
	},
	methods: {
		showCategoryJob(){
			uniCloud.callFunction({
							name: "category",
							data: {
								category_id:uni.getStorageSync('hotjob_nowCategoryId')!=''?uni.getStorageSync('hotjob_nowCategoryId'):'',
								type: "showCategoryJob"
							},
							success: (res) => {
								// console.log("error！",res);
								if(res.result.status!=200){
									// console.log("error！",res);
									return;
								}
								//成功
								//赋值
								this.jobslist=res.result.data.data[0].jobsList
							},
							fail: (err) => {
								console.log(err)
							}
						})
		},
		//根据公司的id找到公司姓名并返回
		selectById(value){
			//云函数查找
			uniCloud.callFunction({
							name: "company",
							data: {
								_id:value,
								type: "selectById"
							},
							success: (res) => {
								// console.log("error！",res);
								if(res.result.status!=200){
									// console.log("error！",res);
									return;
								}
								//成功
								//赋值
								// console.log(res.result.data.data[0].comapny_name);
								this.company_name=res.result.data.data[0].comapny_name
								
							},
							fail: (err) => {
								console.log(err)
							}
						})
		},
		showCompany(value){
			return 1
		},
		//显示确认框并查找公司名字
		showModalAndSelectCompany(companyId,job) {
			// console.log("》》》》》》》》》》》》》》》》",job)
			this.job=job
			uniCloud.callFunction({
							name: "company",
							data: {
								_id:companyId,
								type: "selectById"
							},
							success: (res) => {
								// console.log("error！",res);
								if(res.result.status!=200){
									return;
								}
								//成功
								//赋值
								// console.log(res.result.data)
								this.companyName=res.result.data.data[0].whole_company_name
								// console.log(this.companyName)
							},
							fail: (err) => {
								console.log(err)
							}
						})
			this.modelShow = true;
				},
				//格式化当前日期的写法
				getNowDate(){
					var nowDate = new Date();
					 var year = nowDate.getFullYear();
					 var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1)
					  : nowDate.getMonth() + 1;
					 var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
					  .getDate();
					 var dateStr = year + "-" + month + "-" + day;
					 return dateStr;
				},	
				confirm() {
					// console.log("》》》》》》》》》》》》》》》》",this.job)
					// console.log(this.getNowDate())
					// console.log(this.job.job_name)
							//在申请表插入一条数据
							uniCloud.callFunction({
											name: "apply",
											data: {
												user_id:uni.getStorageSync('storage_user')!=''?uni.getStorageSync('storage_user').data[0]._id:'',
												company_id:this.job.c_id,
												job_id:this.job._id,
												state:0,
												company_name:this.companyName,
												job_name:this.job.job_name,
												time:this.getNowDate(),
												type: "addApply"
											},
											success: (res) => {
												// console.log("-----！",res);
												if(res.result.status!=200){
													return;
												}
												//成功
												//赋值
												// console.log(res.result.data)
												// this.companyName=res.result.data.data[0].whole_company_name
												// console.log(this.companyName)
											},
											fail: (err) => {
												console.log(err)
											}
										})
							setTimeout(() => {
								// 3秒后自动关闭
								this.modelShow = false;
								// 如果不想关闭，而单是清除loading状态，需要通过ref手动调用方法
								// this.$refs.uModal.clearLoading();
							}, 3000)
						}
	}
};
</script>

<style>
/* #ifndef H5 */
page {
	height: 100%;
	background-color: #f2f2f2;
}
/* #endif */
</style>

<style lang="scss" scoped>
.order {
	width: 710rpx;
	background-color: #ffffff;
	margin: 20rpx auto;
	border-radius: 20rpx;
	box-sizing: border-box;
	padding: 20rpx;
	font-size: 28rpx;
	.top {
		display: flex;
		justify-content: space-between;
		.left {
			display: flex;
			align-items: center;
			.store {
				margin: 0 10rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
		}
		.right {
			color: $u-type-warning-dark;
		}
	}
	.item {
		display: flex;
		margin: 20rpx 0 0;
	
		.left {
			margin-right: 20rpx;
			image {
				width: 200rpx;
				height: 200rpx;
				border-radius: 10rpx;
			}
		}
		.content {
			.title {
				font-size: 28rpx;
				line-height: 50rpx;
			}
			.type {
				margin: 10rpx 0;
				font-size: 24rpx;
				color: $u-tips-color;
			}
			.delivery-time {
				color: #e5d001;
				font-size: 24rpx;
			}
		}
		.right {
			// background-color: yellow;
			width: 250px;
			margin-left: 10rpx;
			padding-top: 20rpx;
			text-align: right;
			.decimal {
				font-size: 24rpx;
				margin-top: 4rpx;
			}
			.number {
				color: $u-tips-color;
				font-size: 24rpx;
			}
		}
	}
	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
		.total-price {
			font-size: 32rpx;
		}
	}
	.bottom {
		display: flex;
		margin-top: 40rpx;
		padding: 0 10rpx;
		justify-content: space-between;
		align-items: center;
		.btn {
			line-height: 52rpx;
			width: 160rpx;
			border-radius: 26rpx;
			border: 2rpx solid $u-border-color;
			font-size: 26rpx;
			text-align: center;
			color: $u-type-info-dark;
		}
		.evaluate {
			color: $u-type-warning-dark;
			border-color: $u-type-warning-dark;
		}
	}
}

</style>
